package servlet.recipe.page;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import search.Recipe;
import servlet.account.control.InfoCheck;
import servlet.recipe.control.Recipe_rsp;

import java.io.IOException;
import java.util.List;

@WebServlet("/Select")
public class SearchPage extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String keyword = req.getParameter("keyword");
        int style = Integer.parseInt(req.getParameter("style"));
        req.setAttribute("title", keyword);
        InfoCheck infoCheck = new InfoCheck();
        if (infoCheck.checkCredentials(req)) {
            req.setAttribute("Login","Session");
        }
        Recipe_rsp rsq=new Recipe_rsp();
        req.setAttribute("recipes",rsq.recipes_rsp(style,keyword));
        req.getRequestDispatcher("chushi/jsp/select.jsp").forward(req, resp);
    }
}
